package com.yztc.administrator.meishi.adapter;

/*
 * @author: ZTC
 * @Description: baseAdapter适配器
 * @创建时间:  2016/9/10 18:30 
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.administrator.meishi.R;
import com.yztc.administrator.meishi.bean.MeiPai;

import java.util.List;

public class MeiAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<MeiPai> mData;
    private Context mContext;

    public MeiAdapter(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
    }


    //传递数据方法
    public void setData(List<MeiPai> list) {
        this.mData = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData != null ? mData.size():0;
    }

    @Override
    public Object getItem(int position) {
        return mData != null ?mData.get(position): 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        //绑定控件
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.list_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        //绑定数据
        MeiPai meiPai = mData.get(position);
        String cover_pic = meiPai.getRecommend_cover_pic();
        String avatar = meiPai.getAvatar();
        String caption = meiPai.getCaption();
        holder.tvName.setText(caption);
        Glide.with(mContext).load(cover_pic).placeholder(R.drawable.me_05).into(holder.ivShow);
        Glide.with(mContext).load(avatar).placeholder(R.drawable.me_05).into(holder.ivTouxiang);
        return convertView;
    }
    class ViewHolder{
        TextView tvName;
        ImageView ivShow,ivTouxiang;

        public ViewHolder(View converView){
            tvName = (TextView) converView.findViewById(R.id.tv_list);
            ivShow = (ImageView) converView.findViewById(R.id.iv_list);
            ivTouxiang = (ImageView) converView.findViewById(R.id.iv_touxiang);
            }
    }
}
